#!/usr/bin/env python
# Picka, by Anthony Long.
import string, random

cities = open('Lists/cities.txt').readlines()
countries = open('Lists/countries.txt').readlines()
female_first_names = open('Lists/female_first_names.txt').readlines()
male_name_list = open('Lists/male_first_names.txt').readlines()
street_types = open('Lists/street_types.txt').readlines()
surname_list = open('Lists/surnames.txt').readlines()
usernames = open('Lists/usernames.txt').readlines()
zipcodes = open('Lists/zipcodes.txt').readlines()


def special_characters(i):
    """
    This function will pick x amount of special chars
    from the list below.
    """
    l = """!"#$%&'()*+,-./_\:;<=>?@`~[{}?]"""
    return (''.join(random.choice(l)
            for x in xrange(i)))

    
def foreign_characters(i):
    """
    This function will pick x amount of foreign chars
    from the list below, where a is min, and b is max.
    """
    return "Make foreign_test later"


def male_alias_letters_only(i):
    """
    Another way to pick a male name, perhaps for an alias field.
    """
    male_name_list = open('Lists/male_first_names.txt').readlines()
    return random.choice(male_name_list).capitalize().strip()


def salutation():
    """
    This function will return a 'Mr.' or 'Mrs.'
    """
    salutations = ("Mr.", "Mrs.")
    return random.choice(salutations)


def male_middle_name():
    """
    Picks a middle name from a list of male names.
    """
    male_name_list = open('Lists/male_first_names.txt').readlines()
    return random.choice(male_name_list).capitalize().strip()


def suffix():
    """
    This a suffix from a small list.
    """
    suffix_list = ("Sr.", "Jr.", "II", "III")
    return random.choice(suffix_list)


def set_of_initials(i):
    """
    Returns initials in the A.L. format.
    Use 2 for A.L. format.
    Use 3 for A.J.L. format.
    """
    def _i():
        return random.choice(string.letters).capitalize()
    
    if i == 2:
        return '%s.%s.' % (_i(), _i())
    if i == 3:
        return '%s.%s.%s.' %(_i(), _i(), _i())
    else:
        print "Please pick 2 or 3."

    
def full_male_name():
    """
    This function will pick a first and last male name.
    """
    return "%s %s" % (random.choice(male_name_list).capitalize().strip(),
                        random.choice(surname_list).capitalize().strip())


def full_male_name_with_middle_initial():
    """
    This function will pick a first, middle initial and last male name.
    """
    return "%s %s. %s" % (random.choice(male_name_list).capitalize().strip(),
                        random.choice(string.letters).capitalize(),
                        random.choice(surname_list).capitalize().strip())


def url(i, extension=".com"):
    """
    This function will create a website url, with a default of .com
    To use another extension, do picka.url(10, ".net")
    """
    return ''.join(random.choice(string.letters)
                    for x in range(i)).lower() + extension

    
def aol_screename(a, b):
    """
    Makes an aol screename, which are between 3 to 16 chars in length.
    Feel free to set your own range, like: picka.aol_screename(3, 20)
    """
    return ''.join(random.sample(string.letters, random.choice(range(a, b))))


def month():
    """
    Selects a month for you.
    """
    months = (  "January", "February", "March", "April", 
                "May", "June", "July", "August", "September", 
                "October", "November", "December")
    return random.choice(months)


def month_and_day():
    """
    Selects and month and day for you.
    There is logic to handle the days in the month correctly.
    """
    month_choice = month()
    if month_choice in ("January", "March", "May", "July", "August", "October", "December"):
        return '%s %s' % (month_choice, random.randrange(1, 32))
    if month_choice in ("February"):
        return '%s %s' % (month_choice, random.randrange(1, 29))
    else:
        return '%s %s' % (month_choice, random.randrange(1, 31))


def month_and_day_and_year(a="1900", b="2010"):
    """
    Selects a monday, day and year for you.
    Logic built in to handle day in month.
    To change month do (a, b). b has +1 so the
    last year in your range can be selected. Default is 1900, 2010.
    """
    month_and_day_choice = month_and_day()
    return '%s %s' % (month_and_day_choice, random.randrange(a, b+1))


def gender():
    l = ("Male", "Female")
    return random.choice(l)


def language():
    l = ("English", "Spanish", "French")
    return random.choice(l)


def random_string(i):
    """
    This will allow you to enter an integer, and create 'i' amount
    of characters. ie: random_string(7) = DsEIzCd
    """
    return ''.join(random.choice(string.letters) for x in xrange(i))


def male_name():
    """
    This function will return a male name from a list
    ie - male_name() = 'Anthony'
    """
    male_name_list = open('Lists/male_first_names.txt').readlines()
    return random.choice(male_name_list).capitalize().strip()

def female_name():
    """
    This function will return a female name from a list.
    ie - female_name() = 'Laura'
    """
    female_name_list = open('Lists/female_first_names.txt').readlines()
    return random.choice(female_name_list).capitalize().strip()

def last_name(self):
    """
    This function will return a last name from a list.
    ie - last_name() = 'Smith'.
    """
    last_name_list = open('Lists/surnames.txt').readlines()
    return random.choice(last_name_list).capitalize().strip()

def hyphenated_last_name(self):
    """
    This function will pick 2 random last names and hyphenate them.
    ie - hyphenated_last_name() = 'Perry-Jenkins'
    """
    return '%s-%s' % (self.last_name(), self.last_name())

def initial(self):
    """
    This function will return a capitalized letter with a '.'
    ie - A.
    """
    return '%s.' % random.choice(string.letters).capitalize().strip()


def phone_number(self):
    """
    This function will produce a phone number randomnly, with '-'s.
    """
    x = ''.join(str(random.randrange(10)) for i in xrange(10))
    y = "%s-%s-%s" % (x[0:3], x[3:6], x[6:])
    return y

def zipcode(self):
    """
    This function will pick a zipcode randomnly from a list.
    ie - zipcode() = '11221'.
    """
    zipcode_list = open('Lists/zipcodes.txt').readlines()
    return random.choice(zipcode_list).strip()

def social_security_number(self):
    """
    This function will produce a Mock Social Security Number.
    ie - social_security_number() = '112-32-3322'
    """
    return '%.3i-%.2i-%.4i' % (random.randrange(999), random.randrange(99), random.randrange(9999))

def age(self):
    """
    This function will produce a randomized age.
    ie - age() = '25'
    """
    return '%.2i' % random.randrange(99)
    
def number(self, i):
    """
    This function will produce a random number with as many
    characters as you wish.
    """
    return '%.*i' % (i, random.randrange(i))

def email(self, i, default_email="@example.com"):
    """
    This function will return an email with a default of
    @example.com as a domain.
    """
    if default_email == "@example.com":
        return (''.join(random.choice(string.letters)
                for x in xrange(i)) + default_email)
    else:
        return (''.join(random.choice(string.letters)
                for x in xrange(i)) + default_email)


def city_with_state(self):
    """This function produces a city with a state.
    ie - city_with_state() = 'New York, NY' """
    return random.choice(cities)

def state_abbreviated(self):
    """This function produces just a state abbreviation.
    
    ie - state_abbreviated() = 'NY' """
    temp_city_with_state = self.city_with_state()
    return temp_city_with_state.split(",")[1].strip()

def city(self):
    """This function will produce a city.
    
    ie - city() = 'Brooklyn' """
    temp_city_with_state = self.city_with_state()
    return temp_city_with_state.split(",")[0].strip()

def country(self):
    """This function will produce a city from a list, randomnly.
    
    ie- country() = 'America' """
    
    return random.choice(countries)




def street_type(self):
    """This function will return street types.
    ie- street_type() = 'Alley' """
    return 


def _street_name(self):
    return random.choice([
            ' '.join([self.name.male_name(), self.street_type()]),
            ' '.join([self.name.female_name(), self.street_type()])
        ])
    

def street_address(self):
    """
    This function will produce a complete address 1.
    ie - street_address() = '83-32 Morgan Lane'
    """
    return random.choice([
            '%d-%d %s' % (random.randrange(999), random.randrange(999), self._street_name()),
            '%d %s' % (random.randrange(999), self._street_name()),
            '%s %d, %s' % ("P.O. Box", random.randrange(999), self._street_name()),
            #"P.O. Box " + str(number) + " " + ' '.join([name.female_name(), self.street_type()]),
        ])
    

def apartment_number(self):
    """
    This function will produce an apartment or suite address.
    ie- apartment_generator() = 'Apt. 2L'
    """
    return random.choice([
            "%s%d%s" % ("Apt. ", random.randrange(999), random.choice(string.letters)),
            "%s%d" % ("Suite ", random.randrange(9999)),
            ])
        